<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        window.onload = function() {
            var btn = document.querySelector("button");
            var btn = document.addEventListener("click", function() {
                var form = document.getElementsByTagName("form");
                // console.log(form);
                var username = form[0].getElementsByClassName("username");
                // console.log(username);
                console.log("你的姓名：" + username[0].value);
                var age = form[0].getElementsByClassName("age");
                console.log("你的年龄:" + age[0].value);
                var hobby = form[0].getElementsByClassName("hobby");
                console.log("你的爱好:游戏" + hobby[0].checked);
                console.log("你的爱好:睡觉" + hobby[1].checked);
                console.log("你的爱好:美食" + hobby[2].checked);
                var sex = form[0].getElementsByClassName("sex");
                console.log("你的性别:男" + sex[0].checked);
                console.log("你的性别:女" + sex[1].checked);
                var textarea = form[0].getElementsByClassName("textarea");
                console.log("你的建议:" + textarea[0].value);
            })
        }
    </script>
</head>

<body>
    <h1>调查问卷</h1>
    <form action="">
        <label>姓名:</label><input type="text" class="username" />
        <label>年龄:</label>
        <select class="age">
            <option>11</option>
            <option>22</option>
            <option>33</option>
        </select>
        <label>爱好:</label>
        <label>游戏</label><input type="checkbox" class="hobby" />
        <label>睡觉</label><input type="checkbox" class="hobby" />
        <label>美食</label><input type="checkbox" class="hobby" />
        <label>男:</label><input type="radio" class="sex" />
        <label>女:</label><input type="radio" class="sex" />
        <br>
        <label for="">建议</label><br><textarea class="textarea" rows="3" cols="20"></textarea>
    </form>
    <button>提交</button>
</body>


</html>